﻿using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TpBaseObjects.Base {

    public class SpesenRow {

        #region Members

        private Range myRow;

        #endregion

        #region Constructor

        public SpesenRow(Range row) {
            this.myRow = row;
        }

        #endregion

        #region Properties

        public double Bis {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "D"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "D"];
                r1.Value = value;
            }
        }

        public DateTime Datum {
            get {
                Range r1 = myRow.Cells[1, "A"];
                DateTime ret = new DateTime(1900, 1, 1);
                if (r1.Value != null) {
                    if (DateTime.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public bool IsEndRow {
            get {
                bool ret = false;
                Range r1 = myRow.Cells[1, "A"];
                DateTime date;
                if (r1.Value != null) {
                    if (!DateTime.TryParse(r1.Value.ToString(), out date)) {
                        if (r1.Value.ToString().Contains("Summen")) {
                            ret = true;
                        }
                    }
                }
                return ret;
            }
        }

        public string Project {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "V"];
                if (r1.Value != null) {
                    ret = r1.Value.ToString();
                    return ret;
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "V"];
                r1.Value = value;
            }
        }

        public double Von {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "C"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "C"];
                r1.Value = value;
            }
        }

        #endregion

    }
}
